#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QToolBar>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 创建菜单栏
    QMenuBar* menuBar = this->menuBar();
    this->setMenuBar(menuBar);

    // 创建菜单
    QMenu* menu = new QMenu("菜单");
    menuBar->addMenu(menu);

    // 创建工具栏
    QToolBar* toolBar = new QToolBar();
    this->addToolBar(toolBar);

    // 创建菜单项
    // 不设置 ToolTip 时，一般默认为该文本，也可以手动设置
    QAction* action1 = new QAction("菜单项1");
    QAction* action2 = new QAction("菜单项2");

    action1->setToolTip("点击返回主页");

    action1->setIcon(QIcon(":/index.png"));
    action2->setIcon(QIcon(":/save.png"));

    menu->addAction(action1);
    menu->addAction(action2);

    toolBar->addAction(action1);
    toolBar->addAction(action2);

    connect(action1, &QAction::triggered, this, &MainWindow::handle1);
    connect(action2, &QAction::triggered, this, &MainWindow::handle2);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle1()
{
    qDebug() << "handle1";
}

void MainWindow::handle2()
{
    qDebug() << "handle2";
}
